package service

import (
	"../model"
	"errors"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"log"
)

var DBEngine *xorm.Engine

/**
 * 初始化
 */
func init() {

	driverName := "mysql"
	dataSourceName := "root:19851218dC@(127.0.0.1:3306)/movie_schema?charset=utf8"
	err := errors.New("")
	DBEngine, err = xorm.NewEngine(driverName, dataSourceName)
	if err != nil {
		log.Fatal(err.Error())
	}

	DBEngine.SetMaxOpenConns(5)
	DBEngine.ShowSQL(true)
	err = DBEngine.Sync2(model.MobileUser{}, model.Community{}, model.Contact{})
	if err != nil {
		log.Fatal(err.Error())
	}
	log.Println("Initialize database success.")
}
